package com.iris.thread.produceConsume;

/**
 * 项目: thinking
 * 包名: com.iris.thread.produceConsume
 * 作者: victor
 * 日期: 2016年10月29日
 * 说明: ProduceConsume
 */
public class ProduceConsume {
	
	private volatile int count=0;
	private volatile int max_count=100;
	private volatile int min_count=1;
	public synchronized void produce() throws InterruptedException{
		if(count>=max_count){
			System.out.println("数据已满");
			wait();
			return;
		}
		count++;
		System.out.println("生产第"+count+"个");
		notifyAll();
	}

	public synchronized void consume() throws InterruptedException{
		if(count<min_count){
			System.out.println("数据量过少");
			wait();
			return;
		}
		System.out.println("消费第"+count+"个");
		count--;
		notifyAll();
		
	}

	public static void main(String[] args) {
		ThreadLocal<String> ll=null;
		ProduceConsume pc=new ProduceConsume();
		Thread p=new Thread(new ProduceThread(pc));
		Thread c=new Thread(new ConsumeThread(pc));
		p.start();
		c.start();
		
		
	}

}
